<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use Qcloud\Cos\Client;

class Common extends Controller{
    public $webconfig;
    Public function _initialize(){
        if(!session('admin_id') || !session('shop_id')){
            $this->redirect('Login/index');
        }
       
        $this->_getconfig();
        
        if(request()->module()=='Admin' && request()->controller()=='Index'){
            return true;
        }
        
        if(request()->module()=='Admin' && request()->controller()=='Admin' && request()->action()=='loginOut'){
            return true;
        }
        
        if(session('privilege') == "*"){
            return true;
        }
        
//        if(session('privilege') != '*' && !in_array(request()->module().'/'.request()->controller().'/'.request()->action(), session('privilege'))){
//            echo '您没有权限访问该方法！';
//            die;
//        }
        $webUrl = get_config_value('weburl');
        // 微信小程序支付配置
        $wxpayRes=db('wxpay_config')->where('id',1)->find();
        $this->wechatPayConfig = [
            // 前面的appid什么的也得保留哦
            'app_id'             => $wxpayRes['appid'],
            'mch_id'             => $wxpayRes['mch_id'],
            'key'                => $wxpayRes['api_key'],
            'cert_path'          => '/www/wwwroot/www.yaoyujiankang.com/cert/apiclient_cert.pem', // 绝对路径！！！！
            'key_path'           => '/www/wwwroot/www.yaoyujiankang.com/cert/apiclient_key.pem',      // 绝对路径！！！！
            'notify_url'         => $webUrl.'/api/Wxpay/wxNotify',     // 你也可以在下单时单独设置来想覆盖它
        ];
    }

    public function _getconfig(){
        $_configres = Db::name('config')->where('ca_id','in','1,2,4,5,10,15,17')->field('ename,value')->select();
        $configres = array();
        foreach ($_configres as $v){
            $configres[$v['ename']] = $v['value'];
        }
        $this->webconfig=$configres;
        $this->assign('configres',$configres);
    }

}